package com.example.fina2202.day09;

public class StudentBinarySearch {
    public static void main(String[] args) {
        Student[] ary = new Student[10];
        for (int i=0;i<ary.length;i++){
            ary[i]=new Student(i+1,"student"+i,20+i);
        }

        Student target = new Student(11,"student8",28);
        int index = search(ary,target);
        System.out.println(index);
    }

    public static int search(Student[] ary,Student target){
        int start=0,end=ary.length-1,middle;
        while (start<=end){
            middle = (end-start)/2+start;
            if (target.compareTo(ary[middle])==0)
                return middle;
            else if (target.compareTo(ary[middle])>0)
                start = middle+1;
            else
                end = middle-1;
        }
        return -1;
    }
}
